package org.wen.soft.generate.model;

import lombok.Data;
import org.wen.soft.asm.handler.SignatureType;
import org.wen.soft.asm.model.LoadField;
import org.wen.soft.generate.util.ExcludeUtil;
import org.wen.soft.generate.util.GStrUtil;

@Data
public class GeneField {
    LoadField loadField;
    int modifier;
    String name;

    // 不带泛型
    String className;                 // com.wen.Demo 或 com.wen.Demo$Child
    String descriptorSimpleName;           // Demo 或 Demo.Child
    String descriptorClassName;             // com.wen.Demo 或 com.wen.Demo.Child
    // 带泛型
    String signatureClassName;        // com.wen.Demo<java.lang.String> 或 com.wen.Demo<java.lang.String>$Child
    String signatureClassSimpleName;  // Demo<String>

    boolean thatMock;                 // 是否需要进行mock代理

    public GeneField(LoadField loadField) {
        this.loadField = loadField;
        this.modifier = loadField.getAccess();
        this.name = loadField.getName();

        String descriptor = loadField.getDescriptor();
        this.className = GStrUtil.descriptorClassName(descriptor);
        this.descriptorSimpleName = GStrUtil.simpleName(className);
        this.descriptorClassName = GStrUtil.classTypeName(className);

        SignatureType signatureType = new SignatureType(loadField.getSignature());
        this.signatureClassName = signatureType.getClassName();
        this.signatureClassSimpleName = signatureType.getSimpleName();


        this.thatMock = !ExcludeUtil.mockFieldExclude(descriptorClassName);

    }

    public String getSignatureClassSimpleName() {
        return signatureClassSimpleName != null ? signatureClassSimpleName : descriptorSimpleName;
    }
}
